package com.yazi.mxz.common.db.dao.impl;


import java.util.HashMap;
import java.util.Map;

import org.hibernate.Criteria;
import org.hibernate.criterion.Restrictions;
import org.springframework.stereotype.Repository;

import com.myframework.smhj.hibernate.dao.BasicDao;

import com.yazi.mxz.common.db.dao.MaterialDao;
import com.yazi.mxz.common.entity.beans.Cook;
import com.yazi.mxz.common.entity.beans.Material;

@Repository("MaterialDao")
public class MaterialDaoImpl extends BasicDao<Material> implements MaterialDao {

	
	public MaterialDaoImpl() {
		super(Material.class);
		
	}

	@Override
	public Criteria getExample(Material material, String searchWord) {
		Criteria c = super.getExample(material, searchWord);
		
		// 关联对象条件
		if (null != material) {
			// 菜谱
			Cook cook = material.getCook();
			if (null != cook) {
				// 菜谱ID
				if (null != cook.getCookId()) {
					c.add(Restrictions.eq("cook.cookId", cook.getCookId()));
				} else {
					// ...菜谱其它条件
				}
			}
			// ...其它关联对象条件
		}
		
		// ...关键字searchWord条件
		return c;
	}

	@Override
	public void deleteByCookId(Long cookId) {
		Map<String, Object> map = new HashMap<String, Object>();
		map.put("cookId", cookId);
		executeUpdate("delByCookIdHql", map);
	}

}
